
#include "rrCintamaniWindow.h"
#include "rrCintamaniDocument.h"

#include "JSObject.h"
#include "variant_list.h"
#include "DOM/Document.h"
#include "global/config.h"
#include "DOM/Window.h"

rrCintamaniWindow::rrCintamaniWindow( const FB::DOM::WindowPtr & Win ) : mWindow(Win)
{
	mDocument = rrCintamaniDocumentPtr( new rrCintamaniDocument( Win->getDocument() ));
}

rrCintamaniWindow::~rrCintamaniWindow()
{

}

rrCintamaniDocumentPtr rrCintamaniWindow::GetDocument() const{
	return mDocument; 
}

void rrCintamaniWindow::Alert( const std::string & text ) const {
	mWindow->callMethod<void>("alert",  FB::variant_list_of(text));
}

std::string rrCintamaniWindow::GetWindowName() const  {
	return mWindow->getProperty<std::string>("name");
}

void rrCintamaniWindow::SetWindowName( const std::string & name ) const {
	mWindow->setProperty("name",name);
}

std::string rrCintamaniWindow::GetHrefStr() const {
	return mWindow->getNode("location")->getProperty<std::string>("href");
}

std::string rrCintamaniWindow::GetHostStr() const {
	return mWindow->getNode("location")->getProperty<std::string>("host");
}

std::string rrCintamaniWindow::GetPathNameStr() const { 
	return mWindow->getNode("location")->getProperty<std::string>("pathname");
}

std::string rrCintamaniWindow::GetHostNameStr() const { 
	return mWindow->getNode("location")->getProperty<std::string>("hostname");
}

std::string rrCintamaniWindow::GetProtocolStr() const { //file: Or http:
	return mWindow->getNode("location")->getProperty<std::string>("protocol");
}

FB::variant rrCintamaniWindow::GetInnerWidth() const
{
	return mWindow->getProperty<FB::variant>("innerWidth");
}

FB::variant rrCintamaniWindow::GetInnerHeight() const
{
	return mWindow->getProperty<FB::variant>("innerHeight");
}